<?php
/**
 * Photo.php
 *
 * 用户相册数据对象模型类.
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://momoger.com/license
 *
 * @category	Momoger
 * @package 	Momoger_Model
 * @author 		Leo
 * @version    	1.0
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */

/** Momoger_Model_Abstract */
//require_once 'Abstract.php';

/**
 * 用户相册模型类, 该类提供用户相册的读取保存等信息接口.
 *
 * @category 	Momoger
 * @package		Momoger_Model
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */
class Momoger_Model_Photo extends Momoger_Model_Abstract {

	/**
	 * 构造函数.
	 *
	 * @param mixed $options 快速设置参数.
	 */
	public function __construct($options = null) {
        parent::__construct($options);
	}

	/**
	 * 获取一个图片记录
	 *
	 * @param int $photo_id 图片ID
	 * @return array
	 */
	public function getPhoto($photo_id) {
		return $this->find($photo_id)->getAll();
	}

	/**
	 * 获取图片列表
	 *
	 * @param int $user_id 用户ID, 图片拥有者ID
	 * @param int $category_id 图片分类ID
	 * @param array|string $order 图片排序
	 * @param int $limit 总数限制
	 * @param int $offset 结果开始位置
	 * @return array
	 */
	public function getPhotos($user_id = 0, $category_id = 0, $order = array('photoID DESC'), $limit = 1000, $offset = 0) {
		$where = array();
		if ($user_id) {
			array_push($where, "userID = $user_id");
		}
		if ($category_id) {
			array_push($where, "categoryID = $category_id");
		}
		$models = $this->findAll($where, $order, $limit, $offset);
		$photos = array();
		foreach ($models as $model) {
			array_push($photos, $model->getAll());
		}
		return $photos;
	}

    /**
     * 获取数据地图对象.
     *
     * @return Momoger_Model_Mapper_Photo
     */
    protected function getMapper() {
        if (null === $this->_mapper) {
            $this->setMapper(new Momoger_Model_Mapper_Photo());
        }
        return $this->_mapper;
    }
}